package com.ujs.edu.demo.validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class EmailCodeValidator implements ConstraintValidator<EmailCode,String> {
    @Autowired
    private HttpServletRequest request;
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        String emailCode=(String) request.getSession().getAttribute("emailCode");
        return StringUtils.equals(s,emailCode);
    }
}
